package com.game.sound {
	import com.game.data.Data;
	import com.game.events.GameEvent;
	
	import flash.media.Sound;
	import flash.media.SoundChannel;
	import flash.media.SoundTransform;

	public class SoundManager {
		private var effectsVolume:Number=0.5;
		private var musicVolume:Number=0.5;
		private var channels:Vector.<SoundChannel>;
		private var sounds:Vector.<Sound>;
		public function SoundManager() {
			sounds=Data.getInstance().soundArray;
			channels=new Vector.<SoundChannel>(sounds.length,true);
			Data.getInstance().addEventListener(GameEvent.SOUND_CREATE,onSoundInvoke);
		}
		public function onSoundInvoke(e:GameEvent):void {
			createSound(Data.getInstance().soundAdd);
		}
		private function createSound(id:int):void {
			if (! channels[id] || channels[id].position >= sounds[id].length/2) {
				channels[id] = sounds[id].play();
				channels[id].soundTransform=new SoundTransform(int(	Data.getInstance().volume));
			}
		}
	}
}